    //登录模块
    Route::get('/login','LoginController@showLoginForm');
    Route::post('/login','LoginController@login');
    Route::get('/logout','LoginController@logout');

    class LoginController extends Controller
{

    //登录页面展示
    public function showLoginForm(){
                if(Auth::check()){
            return redirect('/posts');
        }
        return view('home.login.login');
    }

    //登录行为逻辑
    public function login(Request $request){

        $this->validate($request,[
            'email'    => 'required|email',
            'password' => 'required|min:6|max:16',
            'is_remember' => 'integer'
        ]);

        $credentials = [
           'email'    => $request->input('email'),
           'password' => $request->input('password')
        ];

        $is_remember = boolval($request->input('is_remember'));

        if (Auth::attempt($credentials,$is_remember)){
            return redirect('/posts');
        }

        return redirect()->back()->withErrors('邮箱或密码错误')->withInput();
    }

    //登出逻辑
    public function logout(){

        Auth::logout();

        return redirect('/posts');
    }
}

 //视图

     <form class="form-signin" method="POST" action="/login">
         {{ csrf_field() }}
        <h2 class="form-signin-heading">请登录</h2>
        <label for="inputEmail" class="sr-only">邮箱</label>
        <input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
        <label for="inputPassword" class="sr-only">密码</label>
        <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
        <div class="checkbox">
            <label>
                <input type="checkbox" value="1" name="is_remember"> 记住我
            </label>
        </div>

        @include('home.layouts.errors')
        <button class="btn btn-lg btn-primary btn-block" type="submit">登陆</button>
        <a href="/register" class="btn btn-lg btn-primary btn-block" type="submit">去注册>></a>
    </form>


    //判断是否跳转到前后台登录页面 exceptions/hander.php中
protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }
        if(in_array('admin',$exception->guards())){
            return redirect()->guest('admin/login');
        }

        return redirect()->guest('/login');
    }